<?php
/* @var $this SelisteController */
/* @var $model Seliste */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'newmail-form',
	'htmlOptions'=>array('class'=>'form-horizontal'),
	'enableAjaxValidation'=>false,
)); ?>

	<?php $labels = $model->attributeLabels();?>

	<p class="note">Les champs marqués d'une <span class="required">*</span> sont requis.</p>

	<?php echo $form->errorSummary($model,NULL,NULL,array("class"=>"alert alert-danger")); ?>
	
	<div class="form-group">
	    <?php echo $form->labelEx($model,'idseliste_rec',array("class"=>"col-lg-2 control-label")); ?>
	    <div class="col-lg-10">
		    <?php 
		    if ($model->idmessage == NULL) {
			    $data = CHtml::listData(Seliste::model()->findAll(array('condition'=>'id<>'.Yii::app()->user->id.' AND hum=1','order'=>'pseudo asc')),'id',function($seliste) {
			    		$nom = $seliste->id;
			    		if (($seliste->v_pseudo == 1) || ($seliste->v_nom == 1) || ($seliste->v_prenom == 1) || Yii::app()->user->admin) $nom .= " (";
			    		if ($seliste->v_pseudo == 1 || Yii::app()->user->admin) $nom .= $seliste->pseudo;
			    		if (($seliste->v_nom == 1) || ($seliste->v_prenom == 1) || Yii::app()->user->admin) $nom .= " - ";
			    		if ($seliste->v_nom == 1 || Yii::app()->user->admin) $nom .= $seliste->nom . " ";
			    		if ($seliste->v_prenom == 1 || Yii::app()->user->admin) $nom .= $seliste->prenom;
			    		if (($seliste->v_pseudo == 1) || ($seliste->v_nom == 1) || ($seliste->v_prenom == 1) || Yii::app()->user->admin) $nom .= ")";
			    		return $nom;
			    });
			    echo $form->dropDownList($model,'idseliste_rec',$data,array("class"=>"form-control"));
		    } else {
				$seliste = Seliste::model()->findByPk($model->idseliste_rec);
				$nom = $seliste->id;
				if (($seliste->v_pseudo == 1) || ($seliste->v_nom == 1) || ($seliste->v_prenom == 1) || Yii::app()->user->admin) $nom .= " (";
				if ($seliste->v_pseudo == 1 || Yii::app()->user->admin) $nom .= $seliste->pseudo;
				if (($seliste->v_nom == 1) || ($seliste->v_prenom == 1) || Yii::app()->user->admin) $nom .= " - ";
				if ($seliste->v_nom == 1 || Yii::app()->user->admin) $nom .= $seliste->nom . " ";
				if ($seliste->v_prenom == 1 || Yii::app()->user->admin) $nom .= $seliste->prenom;
				if (($seliste->v_pseudo == 1) || ($seliste->v_nom == 1) || ($seliste->v_prenom == 1) || Yii::app()->user->admin) $nom .= ")";
				$data = array($seliste->id=>$nom);
				echo $form->dropDownList($model,'idseliste_rec',$data,array("class"=>"form-control"));
				echo $form->hiddenField($model,"idmessage");
			}
		    ?>
	    </div>
	</div>
	
	 <div class="form-group<?php if ($model->getErrors('sujet')) echo " has-error";?>">
     	<?php echo $form->labelEx($model,'sujet',array("class"=>"col-lg-2 control-label")); ?>
        <div class="col-lg-10"><?php echo $form->textField($model,'sujet',array("class"=>"form-control")); ?></div>
    </div>
    
    <div class="form-group<?php if ($model->getErrors('message')) echo " has-error";?>">
		<?php echo $form->labelEx($model,'message',array("class"=>"col-md-2 control-label")); ?>
		<div class="col-md-10">
			<?php echo $form->textArea($model,'message',array('rows'=>6, 'cols'=>50,'class'=>"form-control")); ?>
		</div>
	</div>

	<div class="form-group">
		<div class="col-lg-offset-2 col-lg-10">
			<?php echo CHtml::submitButton('Envoyer',array("class"=>"btn btn-primary")); ?>
			<?php
			if ($model->idmessage == NULL) { 
				echo CHtml::link("Annuler",array('seliste/mailbox'),array('class'=>"btn btn-sm btn-info"));
			} else {
				echo CHtml::link("Retour au message",array('seliste/mail',"id"=>$model->idmessage),array('class'=>"btn btn-sm btn-info"));
			}	
			?>
		</div>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->